﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BookStore.Solution.BLL;

namespace BookStore.Solution.Presentation
{
    public enum SearchSupplierType
    {
        ID,
        Name,
    }
    public partial class frmSearchSupplier : DevComponents.DotNetBar.OfficeForm
    {
        public DataTable ResultTable { get; set; }
        private SearchSupplierType Type;
        private SupplierManager manager = new SupplierManager();
        public frmSearchSupplier(SearchSupplierType type)
        {
            InitializeComponent();
            this.Type = type;
            switch (type)
            {
                case SearchSupplierType.ID:
                    Text = "Tìm kiếm theo mã nhà cung cấp";
                    break;
                case SearchSupplierType.Name:
                    Text = "Tìm kiếm theo tên nhà cung cấp";
                    break;
            }
        }

        private void frmSearchSupplier_Load(object sender, EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtKeywords.Text != "")
            {
                switch (Type)
                {
                    case SearchSupplierType.ID:
                        ResultTable = manager.SearchByID(txtKeywords.Text);
                        break;
                    case SearchSupplierType.Name:
                        ResultTable = manager.SearchByName(txtKeywords.Text);
                        break;
                }
                if (ResultTable.Rows.Count > 0)
                    Close();
                else
                {
                    MessageBox.Show("Không tìm thấy nhà cung cấp nào.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ResultTable = null;
                }
            }
            else
            {
                txtKeywords.Border.BackColor = Color.Red;
                MessageBox.Show("Chưa nhập từ khóa tìm kiếm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            ResultTable = null;
            Close();
        }

        private void txtKeywords_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnSearch.PerformClick();
        }
    }
}